package com.application.chiettinhdienluc.model;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.ContentResolver;
import android.net.ParseException;
import android.net.Uri;
import android.text.TextUtils;
import android.text.format.DateFormat;

import com.application.chiettinhdienluc.data.GlobalData;

public class ChietTinhModel{

	public static final String CHIETTINH_TABLE_NAME = "HSO_CHIETTINH";

	/**
	 * Content type for account / sip profile
	 */
	public final static String CHIETTINH_CONTENT_TYPE = GlobalData.BASE_DIR_TYPE
			+ ".HSO_CHIETTINH";
	/**
	 * Item type for account / sip profile
	 */
	public final static String CHIETTINH_CONTENT_ITEM_TYPE = GlobalData.BASE_ITEM_TYPE
			+ ".HSO_CHIETTINH";

	public final static Uri CHIETTINH_ID_URI_BASE = Uri
			.parse(ContentResolver.SCHEME_CONTENT + "://"
					+ GlobalData.AUTHORITY + "/" + CHIETTINH_TABLE_NAME + "/");

	public static final String FIELD_CHIETTINH_ID = "rowid";
	public static final String FIELD_BANCTINH_ID = "BANCTINH_ID";
	public static final String FIELD_CPHI_TT = "CPHI_TT";
	public static final String FIELD_CPHI_VT = "CPHI_VT";
	public static final String FIELD_CPHI_VL = "CPHI_VL";
	public static final String FIELD_CPHI_VC = "CPHI_VC";
	public static final String FIELD_CPHI_NC = "CPHI_NC";
	public static final String FIELD_CPHI_MM = "CPHI_MM";
	public static final String FIELD_CPHI_TTK = "CPHI_TTK";
	public static final String FIELD_CPHI_C = "CPHI_C";
	public static final String FIELD_CPHI_TL = "CPHI_TL";
	public static final String FIELD_CPHI_K = "CPHI_K";
	public static final String FIELD_TIEN_GTT = "TIEN_GTT";
	public static final String FIELD_TIEN_GTGT = "TIEN_GTGT";
	public static final String FIELD_SO_TIEN = "SO_TIEN";
	public static final String FIELD_LAM_TRON = "LAM_TRON";
	public static final String FIELD_LAN = "LAN";
	public static final String FIELD_TRANG_THAI = "TRANG_THAI";
	public static final String FIELD_THUC_HIEN = "THUC_HIEN";
	public static final String FIELD_MA_DVIQLY = "MA_DVIQLY";
	public static final String FIELD_MA_YCAU_KNAI = "MA_YCAU_KNAI";
	public static final String FIELD_MALOAI_HS = "MALOAI_HS";
	public static final String FIELD_TEN_KHANG = "TEN_KHANG";
	public static final String FIELD_DTHOAI_DVU = "DTHOAI_DVU";
	public static final String FIELD_BB_KSAT = "BB_KSAT";
	public static final String FIELD_NGAY_KSAT = "NGAY_KSAT";
	public static final String FIELD_NVIEN_KS = "NVIEN_KS";
	public static final String FIELD_TTNHA = "TTNHA";
	public static final String FIELD_TTHD = "TTHD";
	public static final String FIELD_MA_TRAM = "MA_TRAM";
	public static final String FIELD_TEN_TRAM = "TEN_TRAM";
	public static final String FIELD_CSUAT_TRAM = "CSUAT_TRAM";
	public static final String FIELD_MA_GCST = "MA_GCST";
	public static final String FIELD_MA_GCSP = "MA_GCSP";
	public static final String FIELD_NGAY_CTINH = "NGAY_CTINH";
	public static final String FIELD_DVI_DTU = "DVI_DTU";
	public static final String FIELD_NGAY_CHINHSUA = "NGAY_CHINHSUA";
	public static final String FIELD_NGAY_SUBMIT = "NGAY_SUBMIT";
	public static final String FIELD_TRANG_THAI_HSO = "TRANG_THAI_HSO";
	public static final String FIELD_DIA_CHI = "DIA_CHI";
	public static final String FIELD_NGAY_ND = "NGAY_ND";

	public final static String[] CHIETTINH_FULL_PROJECTION = {
		ChietTinhModel.FIELD_BANCTINH_ID, ChietTinhModel.FIELD_CPHI_TT,
		ChietTinhModel.FIELD_CPHI_VT, ChietTinhModel.FIELD_CPHI_VL,
		ChietTinhModel.FIELD_CPHI_VC, ChietTinhModel.FIELD_CPHI_NC,
		ChietTinhModel.FIELD_CPHI_MM, ChietTinhModel.FIELD_CPHI_TTK,
		ChietTinhModel.FIELD_CPHI_C, ChietTinhModel.FIELD_CPHI_TL,
		ChietTinhModel.FIELD_CPHI_K, ChietTinhModel.FIELD_TIEN_GTT,
		ChietTinhModel.FIELD_TIEN_GTGT, ChietTinhModel.FIELD_SO_TIEN,
		ChietTinhModel.FIELD_LAM_TRON, ChietTinhModel.FIELD_LAN,
		ChietTinhModel.FIELD_TRANG_THAI, ChietTinhModel.FIELD_THUC_HIEN,
		ChietTinhModel.FIELD_MA_DVIQLY, ChietTinhModel.FIELD_MA_YCAU_KNAI,
		ChietTinhModel.FIELD_MALOAI_HS, ChietTinhModel.FIELD_TEN_KHANG,
		ChietTinhModel.FIELD_DTHOAI_DVU, ChietTinhModel.FIELD_BB_KSAT,
		ChietTinhModel.FIELD_NGAY_KSAT, ChietTinhModel.FIELD_NVIEN_KS,
		ChietTinhModel.FIELD_TTNHA, ChietTinhModel.FIELD_TTHD,
		ChietTinhModel.FIELD_MA_TRAM, ChietTinhModel.FIELD_TEN_TRAM,
		ChietTinhModel.FIELD_CSUAT_TRAM, ChietTinhModel.FIELD_MA_GCST,
		ChietTinhModel.FIELD_MA_GCSP, ChietTinhModel.FIELD_NGAY_CTINH,
		ChietTinhModel.FIELD_DVI_DTU, ChietTinhModel.FIELD_NGAY_CHINHSUA,
		ChietTinhModel.FIELD_NGAY_SUBMIT, ChietTinhModel.FIELD_TRANG_THAI_HSO,
		ChietTinhModel.FIELD_DIA_CHI, ChietTinhModel.FIELD_NGAY_ND,
		FIELD_CHIETTINH_ID};		

	// Empty constructor
	public ChietTinhModel() {
	}
	
	public void cloneObject(ChietTinhModel object)
	{
		this._Id = object.get_Id();
		this.banctinhId = object.get_MaBanChietTinh();
		this._ChiPhiTT = object.get_ChiPhiTT();
		this._ChiPhiVT = object.get_ChiPhiVT();
		this._ChiPhiVL = object.get_ChiPhiVL();
		this._ChiPhiVC = object.get_ChiPhiVC();
		this._ChiPhiNC = object.get_ChiPhiNC();
		this._ChiPhiMM = object.get_ChiPhiMM();
		this._ChiPhiTTK = object.get_ChiPhiTTK();
		this._ChiPhiC = object.get_ChiPhiC();
		this._ChiPhiTL = object.get_ChiPhiTL();
		this._ChiPhiK = object.get_ChiPhiK();
		this._TienGTT = object.get_TienGTT();
		this._TienGTGT = object.get_TienGTGT();
		this._SoTien = object.get_SoTien();
		this._LamTron = object.get_LamTron();
		this.lan =object.get_Lan();
		this.trangThai = object.get_TrangThai();
		this.thucHien = object.get_ThucHien();
		this.maDviqly = object.get_MaDonViQuanLy();
		this.maYcauKnai = object.get_MaYeuCauKhieuNai();
		this.maLoaiHs = object.get_MaLoaiHoSo();
		this.tenKhang = object.get_TenKhachHang();
		this.dthoaiDvu = object.get_DienThoaiDichVu();
		this.diaChi = object.get_DiaChi();
		this.ngayND = object.get_NgayND();
		
		this.bbKsat = object.get_BienBanKhaoSat();
		this.ngayKsat = object.get_NgayKhaoSat();
		this.ttnha = object.get_ThongTinNha();
		this.nvienKs = object.get_NhanVienKhaoSat();
		this.tthd = object.get_ThongTinHopDong();
		this.maTram = object.get_MaTram();
		this.tenTram = object.get_TenTram();
		this.csuatTram = object.get_CongSuatTram();
		this.maGcst = object.get_MaGCST();
		this.maGcsp = object.get_MaGCSP();
		this.ngayCtinh = object.get_NgayChietTinh();
		this.dviDtu = object.get_DonViDauTu();
		this.ngayChinhSua = object.get_NgayChinhSua();
		this.ngaySubmit = object.get_NgaySubmit();
		this.trangThaiHoso = object.get_TrangThaiHoSo();
	}

	// private variables
	private long _Id = 0;
	private String banctinhId = "";
	private double _ChiPhiTT = 0;
	private double _ChiPhiVT = 0;
	private double _ChiPhiVL = 0;
	private double _ChiPhiVC = 0;
	private double _ChiPhiNC = 0;
	private double _ChiPhiMM = 0;
	private double _ChiPhiTTK = 0;
	private double _ChiPhiC = 0;
	private double _ChiPhiTL = 0;
	private double _ChiPhiK = 0;
	private double _TienGTT = 0;
	private double _TienGTGT = 0;
	private double _SoTien = 0;
	private double _LamTron = 0;
	private int lan = 0;
	private String trangThai = "";
	private String thucHien = "";
	private String maDviqly = "";
	private String maYcauKnai = "";
	private String maLoaiHs = "";
	private String tenKhang = "";
	private String dthoaiDvu = "";
	private String bbKsat = "";
	private String ngayKsat = "";
	private String nvienKs = "";
	private String ttnha = "";
	private String tthd = "";
	private String maTram = "";
	private String tenTram = "";
	private String csuatTram = "";
	private String maGcst = "";
	private String maGcsp = "";
	private String ngayCtinh = "";
	private String dviDtu = "";
	private String ngayChinhSua = "";
	private String ngaySubmit = "";
	private String trangThaiHoso = "";
	private String diaChi = "";
	private String ngayND = "";
	private boolean isCheckToDelete = false;
	
	public boolean isCheckToDelete() {
		return isCheckToDelete;
	}

	public void setCheckToDelete(boolean isCheckToDelete) {
		this.isCheckToDelete = isCheckToDelete;
	}

	private boolean _hasChanged = false;

	
	
	public boolean hasChanged() {
		return _hasChanged;
	}
	
	public long get_Id() {
		return _Id;
	}
	
	public void set_Id(long id) {
		_Id = id;
	}
	
	public String get_MaBanChietTinh() {
		return banctinhId;
	}

	public void set_MaBanChietTinh(String _MaBanChietTinh) {
		this.banctinhId = _MaBanChietTinh;
	}

	public double get_ChiPhiTT() {
		return _ChiPhiTT;
	}

	public void set_ChiPhiTT(double _ChiPhiTT) {
		this._ChiPhiTT = _ChiPhiTT;
	}

	public double get_ChiPhiVT() {
		return _ChiPhiVT;
	}

	public void set_ChiPhiVT(double _ChiPhiVT) {
		this._ChiPhiVT = _ChiPhiVT;
	}

	public double get_ChiPhiVL() {
		return _ChiPhiVL;
	}

	public void set_ChiPhiVL(double _ChiPhiVL) {
		this._ChiPhiVL = _ChiPhiVL;
	}

	public double get_ChiPhiVC() {
		return _ChiPhiVC;
	}

	public void set_ChiPhiVC(double _ChiPhiVC) {
		this._ChiPhiVC = _ChiPhiVC;
	}

	public double get_ChiPhiNC() {
		return _ChiPhiNC;
	}

	public void set_ChiPhiNC(double _ChiPhiNC) {
		this._ChiPhiNC = _ChiPhiNC;
	}

	public double get_ChiPhiMM() {
		return _ChiPhiMM;
	}

	public void set_ChiPhiMM(double _ChiPhiMM) {
		this._ChiPhiMM = _ChiPhiMM;
	}

	public double get_ChiPhiTTK() {
		return _ChiPhiTTK;
	}

	public void set_ChiPhiTTK(double _ChiPhiTTK) {
		this._ChiPhiTTK = _ChiPhiTTK;
	}

	public double get_ChiPhiC() {
		return _ChiPhiC;
	}

	public void set_ChiPhiC(double _ChiPhiC) {
		this._ChiPhiC = _ChiPhiC;
	}

	public double get_ChiPhiTL() {
		return _ChiPhiTL;
	}

	public void set_ChiPhiTL(double _ChiPhiTL) {
		this._ChiPhiTL = _ChiPhiTL;
	}

	public double get_ChiPhiK() {
		return _ChiPhiK;
	}

	public void set_ChiPhiK(double _ChiPhiK) {
		this._ChiPhiK = _ChiPhiK;
	}

	public double get_TienGTT() {
		return _TienGTT;
	}

	public void set_TienGTT(double _TienGTT) {
		this._TienGTT = _TienGTT;
	}

	public double get_TienGTGT() {
		return _TienGTGT;
	}

	public void set_TienGTGT(double _TienGTGT) {
		this._TienGTGT = _TienGTGT;
	}

	public double get_SoTien() {
		return _SoTien;
	}

	public void set_SoTien(double _SoTien) {
		this._SoTien = _SoTien;
	}

	public double get_LamTron() {
		return _LamTron;
	}

	public void set_LamTron(double _LamTron) {
		this._LamTron = _LamTron;
	}

	public int get_Lan() {
		return lan;
	}

	public void set_Lan(int lan) {
		this.lan = lan;
	}

	public String get_TrangThai() {
		return trangThai;
	}

	public void set_TrangThai(String trangThai) {
		this.trangThai = trangThai;
	}

	public String get_ThucHien() {
		return thucHien;
	}

	public void set_ThucHien(String thucHien) {
		this.thucHien = thucHien;
	}

	public String get_MaDonViQuanLy() {
		return maDviqly;
	}

	public void set_MaDonViQuanLy(String maDviqly) {
		this.maDviqly = maDviqly;
	}

	public String get_MaYeuCauKhieuNai() {
		return maYcauKnai;
	}

	public void set_MaYeuCauKhieuNai(String maYcauKnai) {
		this.maYcauKnai = maYcauKnai;
	}

	public String get_MaLoaiHoSo() {
		return maLoaiHs;
	}

	public void set_MaLoaiHoSo(String maLoaiHs) {
		this.maLoaiHs = maLoaiHs;
	}

	public String get_TenKhachHang() {
		return tenKhang;
	}

	public void set_TenKhachHang(String tenKhang) {
		if(!tenKhang.equalsIgnoreCase(tenKhang))
			_hasChanged = true;
		
		this.tenKhang = tenKhang;
	}
		
	public String get_DiaChi() {
		return diaChi;
	}

	public void set_DiaChi(String diaChi) {
			
		this.diaChi = diaChi;
	}	
	
	public String get_NgayND() {
		return ngayND;
	}
	
	public String get_FormattedNgayND() {
		
		String formattedDate;
		
		Date date = null;
		
		try {
			date = new SimpleDateFormat("dd/MM/yyyy").parse(ngayND);
		} catch (java.text.ParseException e) {
			
			e.printStackTrace();
		} 	 
			
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		formattedDate = sdf.format(date);			
		
		return formattedDate;
		
	}
	
	

	public void set_NgayND(String ngayND) {
		this.ngayND = ngayND;
	}

	public String get_DienThoaiDichVu() {
		return dthoaiDvu;
	}

	public void set_DienThoaiDichVu(String dthoaiDvu) {
		this.dthoaiDvu = dthoaiDvu;
	}

	public String get_BienBanKhaoSat() {
		return bbKsat;
	}

	public void set_BienBanKhaoSat(String bbKsat) {
		this.bbKsat = bbKsat;
	}

	public String get_NgayKhaoSat() {
		return ngayKsat;
	}
	
	public String get_FormattedNgayKhaoSat() {
				
		String formattedDate;
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		if (!TextUtils.isEmpty(ngayKsat)) {
			Date date = null;
			
			try {
				date = new SimpleDateFormat("dd/MM/yyyy").parse(ngayKsat);
			} catch (java.text.ParseException e) {
				
				e.printStackTrace();
			} 	 
				
			
			formattedDate = sdf.format(date);
		}
		else
		{
		   //get current date time with Date()
		   Date cDate = new Date();
		   
		   formattedDate = sdf.format(cDate);
			
		}
		
		return formattedDate;
	}
	

	public void set_NgayKhaoSat(String ngayKsat) {
		this.ngayKsat = ngayKsat;
	}

	public String get_NhanVienKhaoSat() {
		return nvienKs;
	}

	public void set_NhanVienKhaoSat(String nvienKs) {
		this.nvienKs = nvienKs;
	}

	public String get_ThongTinNha() {
		return ttnha;
	}

	public void set_ThongTinNha(String ttnha) {
		this.ttnha = ttnha;
	}

	public String get_ThongTinHopDong() {
		return tthd;
	}

	public void set_ThongTinHopDong(String tthd) {
		this.tthd = tthd;
	}

	public String get_MaTram() {
		return maTram;
	}

	public void set_MaTram(String maTram) {
		this.maTram = maTram;
	}

	public String get_TenTram() {
		return tenTram;
	}

	public void set_TenTram(String tenTram) {
		this.tenTram = tenTram;
	}

	public String get_CongSuatTram() {
		return csuatTram;
	}

	public void set_CongSuatTram(String csuatTram) {
		this.csuatTram = csuatTram;
	}

	public String get_MaGCST() {
		return maGcst;
	}

	public void set_MaGCST(String maGcst) {
		this.maGcst = maGcst;
	}

	public String get_MaGCSP() {
		return maGcsp;
	}

	public void set_MaGCSP(String maGcsp) {
		this.maGcsp = maGcsp;
	}

	public String get_NgayChietTinh() {
		return ngayCtinh;
	}
	
    public String get_FormattedNgayChietTinh() {
			
		
    	
       String formattedDate;
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		if (!TextUtils.isEmpty(ngayCtinh)) {
			Date date = null;
			
			try {
				date = new SimpleDateFormat("dd/MM/yyyy").parse(ngayCtinh);
			} catch (java.text.ParseException e) {
				
				e.printStackTrace();
			} 	 
				
			
			formattedDate = sdf.format(date);
		}
		else
		{
		   //get current date time with Date()
		   Date cDate = new Date();
		   
		   formattedDate = sdf.format(cDate);
			
		}
		
		return formattedDate;
	}

	public void set_NgayChietTinh(String ngayCtinh) {
		this.ngayCtinh = ngayCtinh;
	}

	public String get_DonViDauTu() {
		return dviDtu;
	}

	public void set_DonViDauTu(String dviDtu) {
		this.dviDtu = dviDtu;
	}

	public String get_NgayChinhSua() {
		return ngayChinhSua;
	}

	public void set_NgayChinhSua(String ngayChinhSua) {
		this.ngayChinhSua = ngayChinhSua;
	}

	public String get_NgaySubmit() {
		return ngaySubmit;
	}

	public void set_NgaySubmit(String ngaySubmit) {
		this.ngaySubmit = ngaySubmit;
	}

	public String get_TrangThaiHoSo() {
		return trangThaiHoso;
	}

	public void set_TrangThaiHoSo(String trangThaiHoso) {
		this.trangThaiHoso = trangThaiHoso;
	}
	
	public boolean isEqualObject(ChietTinhModel object)
	{
		boolean result = true; // default is equal
		
		if(this._Id != object.get_Id()) return false;
		if(!this.banctinhId.equals(object.get_MaBanChietTinh())) return false;
		if(!this.maYcauKnai.equals(object.get_MaYeuCauKhieuNai())) return false;
		if(!this.tenKhang.equals(object.get_TenKhachHang())) return false;
		if(!this.diaChi.equals(object.get_DiaChi())) return false;
		if(!this.dthoaiDvu.equals(object.get_DienThoaiDichVu())) return false;
		if(!this.ngayND.equals(object.get_NgayND())) return false;
		if(!this.trangThaiHoso.equals(object.get_TrangThaiHoSo())) return false;
		if(!this.dviDtu.equals(object.get_DonViDauTu())) return false;
		
		if(!this.ngayKsat.equals(object.get_NgayKhaoSat())) return false;
		if(!this.bbKsat.equals(object.get_BienBanKhaoSat())) return false;
		if(!this.maGcst.equals(object.get_MaGCST())) return false;
		if(!this.maGcsp.equals(object.get_MaGCSP())) return false;
		if(!this.maTram.equals(object.get_MaTram())) return false;
		if(!this.tenTram.equals(object.get_TenTram())) return false;
		if(!this.csuatTram.equals(object.get_CongSuatTram())) return false;
		if(!this.maLoaiHs.equals(object.get_MaLoaiHoSo())) return false;
		
		if(this._ChiPhiVL != object.get_ChiPhiVL()) return false;
		if(this._ChiPhiVT != object.get_ChiPhiVT()) return false;
		if(this._ChiPhiVC != object.get_ChiPhiVC()) return false;
		if(this._ChiPhiNC != object.get_ChiPhiNC()) return false;
		if(this._ChiPhiMM != object.get_ChiPhiMM()) return false;
		if(this._ChiPhiTTK != object.get_ChiPhiTTK()) return false;
		if(this._ChiPhiTT != object.get_ChiPhiTT()) return false;
		if(this._ChiPhiC != object.get_ChiPhiC()) return false;
		if(this._ChiPhiTL != object.get_ChiPhiTL()) return false;
		if(this._ChiPhiK != object.get_ChiPhiK()) return false;
		if(this._TienGTT != object.get_TienGTT()) return false;
		if(this._TienGTGT != object.get_TienGTGT()) return false;
		if(this._SoTien != object.get_SoTien()) return false;
		
//		if(this._LamTron != object.get_LamTron()) return false;//30/10/2013
//		if(this.lan != object.get_Lan()) return false;
//		if(!this.trangThai.equals(object.get_TrangThai())) return false;
//		if(!this.thucHien.equals(object.get_ThucHien())) return false;
//		if(!this.maDviqly.equals(object.get_MaDonViQuanLy())) return false;
//		if(!this.ttnha.equals(object.get_ThongTinNha())) return false;
//		if(!this.nvienKs.equals(object.get_NhanVienKhaoSat())) return false;
//		if(!this.tthd.equals(object.get_ThongTinHopDong())) return false;
//		if(!this.ngayCtinh.equals(object.get_NgayChietTinh())) return false;
//		if(!this.ngayChinhSua.equals(object.get_NgayChinhSua())) return false;
//		if(!this.ngaySubmit.equals(object.get_NgaySubmit())) return false;
		try {
			if(object.get_Id() <= 0)
			{
				String folderPath = GlobalData.sdcardPath + "/ChietTinh/" + "temp";
				File folder = new File(folderPath);
				
				if(folder != null && folder.exists() && folder.isDirectory())
				{
					File[] files = folder.listFiles();
					
					if(files != null && files.length > 0) return false;
				}
			}
		} catch (Exception e) {
		}
		
		return result;
	}
	
}
